-- 
-- Start Menu
-- 

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local MenuUtils = require 'scripts.utils.MenuUtils'
local menuUtils = MenuUtils.new()

function scene:createScene( event )
   storyboard.removeAll()
   local group = self.view
end

function createMenu(group)
   local background = display.newImageRect( "resources/sprites/menuBG.jpg", X, Y )
   background.x = X*0.5
   background.y = Y*0.5

   local iniGameBtn = menuUtils:createButton(X*0.25, Y*0.6, "PLAY", function ()
      storyboard.gotoScene("scripts.scenes.levelSelectionScene", {effect = "fade",time = 100})
      return true
   end)
   
   local tutorialBtn = menuUtils:createButton(X*0.25, Y*0.6+Y*0.15, "TUTORIAL", function ()
      LEVEL = 1
      storyboard.gotoScene("scripts.scenes.GridTestScene", {effect = "fade",time = 100})
      return true
   end)
   
   local creditosBtn = menuUtils:createButton(X*0.25, Y*0.6+Y*0.3, "CREDITS", function ()
      storyboard.gotoScene("scripts.scenes.credits", {effect = "fade",time = 100})
      return true
   end)

   group:insert( background )
   group:insert( iniGameBtn )
   group:insert( tutorialBtn )
   group:insert( creditosBtn )

   local ads = require "ads"
   local function adListener( event )
       if event.isError then
       end
   end

   local appIDs = {}
   appIDs[1] = "ca-app-pub-2859908357438784/1779213874" -- Edwin Guzman
   appID = math.random(1, #appIDs)
   print(appID)
   ads.init( "admob", appIDs[appID], adListener )
   ads.show( "banner", {
      x = 0,
      y = Y
   } )
end

function scene:enterScene( event )
   local group = self.view

   -- local function listener( event )
   --     local teamsplash = display.newImageRect( "resources/sprites/globalsplash.jpg", X, Y )
   --    teamsplash.x = X*0.5
   --    teamsplash.y = Y*0.5
   -- end
   -- timer.performWithDelay( 1000, listener )
   -- local globalsplash = display.newImageRect( "resources/sprites/globalsplash.jpg", X, Y )
   -- globalsplash.x = X*0.5
   -- globalsplash.y = Y*0.5

   createMenu(group)
end

function scene:exitScene( event )
   local group = self.view
end

function scene:destroyScene( event )
   local group = self.view
end

scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )

return scene
